package barinadroid.game;

import java.util.ArrayList;

public class EnemyFactory
{
	public static EnemyFactory instance;

	public static EnemyFactory getSharedInstance()
	{
		if(instance == null)
			instance = new EnemyFactory();
		return instance;
	}

	private ArrayList<Enemy> enemies;
	private EnemyPool pool;

	private EnemyFactory()
	{
		enemies = new ArrayList<Enemy>();
		pool = EnemyPool.sharedBulletPool();
	}

	public Enemy Spawn(float x, float y)
	{
		Enemy enemy = pool.obtainPoolItem();
		enemy.setPosition(x, y);
		enemies.add(enemy);
		return enemy;
	}

	public ArrayList<Enemy> getEnemies()
	{
		return this.enemies;
	}

	public void KillEnemy(Enemy enemy)
	{
		enemy.setActive(false);
		enemy.detachSelf();
		pool.recyclePoolItem(enemy);
		enemies.remove(enemy);
	}

	public void KillAllEnemies()
	{
		for(Enemy enemy : enemies)
		{
			enemy.setActive(false);
			enemy.detachSelf();
			pool.recyclePoolItem(enemy);
		}
		enemies.clear();
	}
}